/**
 * 医嘱套(组)管理初始化
 */
var CdcOrdgroup = {
    id: "CdcOrdgroupTable",	//表格id
    groupId:0,
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CdcOrdgroup.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '索引码', field: 'xcode', align: 'center', valign: 'middle', sortable: true,width:80},
        {title: '代码', field: 'code', align: 'center', valign: 'middle', sortable: true,width:100},
        {title: '描述', field: 'description', align: 'center', valign: 'middle', sortable: true,width:220},
        {title: '是否有效', field: 'isActive', align: 'center', valign: 'middle', sortable: true,formatter:function(value,row,index) {
            return value?"是":"否";
        },width:80}
    ];
};

/**
 * 检查是否选中
 */
CdcOrdgroup.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        CdcOrdgroup.seItem = selected[0];
        return true;
    }
};

/**
 * 点击新增医嘱套(组)
 */
CdcOrdgroup.add = function () {
    var index = Sys.open('新增医嘱套(组)',Sys.backendPath + '/cdc/cdcordgroup/to_add',['500px', '330px']);
    this.layerIndex = index;
};

/**
 * 打开查看医嘱套(组)详情
 */
CdcOrdgroup.edit = function (id) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        flag = true;
    }
	if (flag) {
    	var index = Sys.open('医嘱套(组)详情',Sys.backendPath + '/cdc/cdcordgroup/to_update/' + id,['500px', '330px']);
        this.layerIndex = index;
    }
};
CdcOrdgroup.entry = function (id,desc) {
    CdcOrdgroup.groupId=id;
    var index = Sys.open('当前编辑医嘱套：'+desc,Sys.backendPath + '/cdc/cdcordgroup/to_entry',['800px', '480px']);
        this.layerIndex = index;
}

/**
 * 删除医嘱套(组)
 */
CdcOrdgroup.del = function (id,name) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        name = this.seItem.name
        flag = true;
    }
	if (flag) {
        var operation = function(){
	        var ajax = new $ax(Sys.backendPath + "/cdc/cdcordgroup/delete", function (data) {
	            Sys.success("删除成功!");
	            CdcOrdgroup.table.refresh();
	        }, function (data) {
	            Sys.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("cdcOrdgroupId",id);
	        ajax.start();
	    };
	    Sys.confirm("是否删除医嘱套(组)?",operation);
    }
};

/**
 * 查询医嘱套(组)列表
 */
CdcOrdgroup.search = function () {
    var queryData = {};
    queryData['code'] = $("#code").val();
    queryData['description'] = $("#description").val();
    queryData['dataId'] = $("#dataId").val();
    queryData['isActive'] = $("#isActive").val();
    CdcOrdgroup.table.refresh({query: queryData});
};
CdcOrdgroup.ClickRow = function(r,e,f){
    CdcOrdgroupEntry.ordGroupId=r.id;
    CdcOrdgroupEntry.table.clear();
    CdcOrdgroupEntry.table.refresh({query: {orderGroupId:r.id}});
}
$(function () {
    CdcOrdgroup.sysDataId=window.parent.baseData.sysDataId;

    var defaultColunms = CdcOrdgroup.initColumn();
    var table = new BSTable(CdcOrdgroup.id, Sys.backendPath + "/cdc/cdcordgroup/list", defaultColunms);
    table.setPaginationType("server");
    table.setShowRefresh(false);
    table.setShowColumns(false);
    table.setShowToggle(false);
    table.setPageSize(10);
    table.setSubHead(5);
    table.setOnClickRow(CdcOrdgroup.ClickRow);
    table.setQueryParams({ "dataId": CdcOrdgroup.sysDataId });
    CdcOrdgroup.table = table.init();
});
